/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.commands.account;

import com.bionic.commands.common.ICommand;
import com.bionic.dao.AccountDAO;
import com.bionic.dao.UserDAO;
import com.bionic.entity.Account;
import com.bionic.entity.Users;
import com.bionic.manager.Config;
import com.bionic.manager.Message;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Obuhov D.G.
 */
public class CAccount implements ICommand {

    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String page = null; //  Config.getInstance().getProperty(Config.LOGIN);

        HttpSession session = request.getSession();
        Users user = (Users) session.getAttribute("currentUser");

        if ((user!=null)&&(user.getId() != null)) {
            AccountDAO accountDAO = new AccountDAO();
            ArrayList<Account> accountList = new ArrayList();

            accountList = accountDAO.findByUserId(user.getId());
            request.setAttribute("accountList", accountList);

            page = Config.getInstance().getProperty(Config.ACCOUNTS_VIEW);
        } else {
            page = Config.getInstance().getProperty(Config.LOGIN);
        }

        return page;
    }
}
